<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String isShow = request.getParameter("isShow") == null ? "" : request.getParameter("isShow");
    String gd_content_id = request.getParameter("gd_content_id") == null ? "" : request.getParameter("gd_content_id");
    String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
    String gd_description_id = request.getParameter("gd_description_id") == null ? "" : request.getParameter("gd_description_id");
    boolean isAdd = "".equals(gd_description_id);
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<html>
	<head>
		<title><%=isAdd?"新建交底":"编辑交底" %></title>
		<link href="<%=contextPath%>/public/css/smart_wizard_vertical.css" rel="stylesheet"	type="text/css">
		<script type="text/javascript" src="<%=contextPath%>/public/js/jquery.smartWizard.js"></script>
		<link  rel="stylesheet"  href  ="<%=contextPath%>/public/swfupload/css/swfupload.css">
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
		</style>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/datastructs.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/sys.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/prototype.js"  ></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/attachMenu.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/Menu.js"></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/fileprogress.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/handlers.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.queue.js"  ></script>
			  <script type="text/javascript" charset="utf-8" src="<%=contextPath%>/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=contextPath%>/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="<%=contextPath%>/ueditor/lang/zh-cn/zh-cn.js"></script>
        <script type="text/javascript" charset="utf-8" src="<%=contextPath%>/ueditor/edit.js"> </script>
		<script type="text/javascript">
			var swfupload;
			var flag = '<%=flag%>';
			jQuery(document).ready(function() {
				if(flag == '1'){
					jQuery('#gdForm').form({
						onLoadSuccess:function(){
							queueCompleteOver();
						}
					});
					jQuery('#gdForm').form("load",'<%=contextPath %>/springMVC/gd/getGDDescriptionById?gd_description_id=<%=gd_description_id%>');
				}else{
				    jQuery("#description_time").datebox('setValue',getTodaySecond());
				}
					var settings = {
				      flash_url : "<%=contextPath%>/public/swfupload/swfupload.swf",
				      upload_url: "<%=contextPath%>/springMVC/fileUpload/fileupload",
				      post_params: {
				    	 "module" : "<%=com.beaut.project.util.StaticData.GD_MODULE%>"
				      },
				      file_size_limit : "100 MB",
				      file_types : "*.*",
				      file_types_description : "All Files",
				      file_upload_limit : 100,
				      file_queue_limit : 0,
				      custom_settings : {
				        uploadArea : "fsUploadArea",
				        progressTarget : "fsUploadProgress",
				        startButtonId : "btnStart",
				        cancelButtonId : "btnCancel"
				      },
				      debug: false,
				      button_image_url: "<%=contextPath%>/public/swfupload/img/uploadx4.gif",
				      button_width: "65",
				      button_height: "29",
				      button_placeholder_id: "spanButtonUpload",
				      button_text: '<span class=\"textUpload\">上传附件</span>',
				      button_text_style: ".textUpload{color:#0000ff;}",
				      button_text_top_padding : 1,
				      button_text_left_padding : 18,
				      button_width: 80,
				      button_height: 20,
				      button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				      button_cursor: SWFUpload.CURSOR.HAND,
				      
				      file_queued_handler : fileQueued,
				      file_queue_error_handler : fileQueueError,
				      file_dialog_complete_handler : fileDialogComplete,
				      upload_start_handler : uploadStart,
				      upload_progress_handler : uploadProgress,
				      upload_error_handler : uploadError,
				      upload_success_handler : uploadSuccessOver,
				      upload_complete_handler : uploadComplete,
				      queue_complete_handler : queueCompleteOver
				    };
				    swfupload = new SWFUpload(settings);
				    
				});
			
		 function uploadSuccessOver(file, serverData){
				  try {
				    var progress = new FileProgress(file, this.customSettings.progressTarget);
				    progress.toggleCancel(false);
				    var json = null;
				    json = serverData.evalJSON();
				    if(json.rtState=="1") {
				       progress.setError();
				       progress.setStatus("上传失败");
				    } else {
				       if($('attachmentId').value!=null && $('attachmentId').value!=""){
				    	 $('attachmentId').value += ',' + json.rtData.attachmentId;
				       } 
				       else{
				    	   $('attachmentId').value = json.rtData.attachmentId;
				       }
				       if($('attachmentName').value!=null && $('attachmentName').value!=""){
				    	 $('attachmentName').value += '*' + json.rtData.attachmentName;
				       } 
				       else{
				    	   $('attachmentName').value = json.rtData.attachmentName;
				       }
				    }
				  } catch (ex) {
				    this.debug(ex);
				  }
		}
		function queueCompleteOver(){
			var attachmentIds = $("attachmentId").value;
		    var attachmentNames = $("attachmentName").value;
		    if(attachmentIds){
		      jQuery('#attaTr').show();
	       	  jQuery('#fsUploadArea').hide();
	       	  if('<%=isShow%>' == 1){
	       	  	attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,true,'attach');
	       	  }else{
	       	  	attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,false,'attach');
	       	  }
		    }
		 }
				 
		  function deleteAttachment(attachmentId,attachmentName){
			  var attrIds = $("attachmentId").value;
		    var attrNames = $("attachmentName").value;
		     var attrIdArrays = attrIds.split(",");
			  var attrNameArrays = attrNames.split("*");
			 var idArray = new Array();
			 var nameArray = new Array();
			 
			 for(var i=0;i<attrIdArrays.length;i++){
				 if(attrIdArrays[i] != attachmentId){
					 idArray.push(attrIdArrays[i]);
					 nameArray.push(attrNameArrays[i]);
				 }
			 }
			 $("attachmentId").value = idArray.join(",");
			 $("attachmentName").value = nameArray.join("*");
			 if($("attachmentId").value == ""){
				 jQuery('#attaTr').hide();
			 }
		  }
		  
		  function addOrEditGdDescription(obj){
			  var content=getContent();
			  jQuery("#content").val(content);
			  jQuery('#gdForm').form('submit',{
				  <%=isAdd?"url:'"+contextPath+"/springMVC/gd/addGDDescription',":"url:'"+contextPath+"/springMVC/gd/updateGDDescription?gd_description_id="+gd_description_id+"',"%>
				  onSubmit: function(){
						var isvalid = jQuery(this).form('validate');
						if(!isvalid){
							jQuery(obj).show();
						}
						return isvalid;
					},
				  success: function(data){
					  var rtJson = eval('(' + data + ')');
					  if(rtJson.rtState == '0'){
							eval('window.opener.rtCallBack();');
							window.close();
						}
						else{
							jQuery.messager.alert("提示",rtJson.rtMsrg);
						}
						jQuery(obj).show();
				  }
			  });
		  }
		  function getContent() {
		       return UE.getEditor('editor').getContent();
		    }
		 function setContent(isAppendTo) {
		    	var content=jQuery("#content").val();
		        UE.getEditor('editor').setContent(content, isAppendTo);
		    }
		 function gdPrint(){
				openDialogResize("<%=contextPath%>/springViews/print/startGdDescriptionPrint.jsp?gd_description_id=<%=gd_description_id%>",1000, 800);
			}
</script>
</head>
<body onload="setContent();">
		<div style="width: 90%;padding-left:50px">
		<form id="gdForm" method="post">
						<input type="hidden" id="gd_id" name="gd_id"  value="<%=gd_id %>">
						<input type="hidden" id="gd_content_id" name="gd_content_id"   value="<%=gd_content_id %>">
			<table  style="border-collapse: collapse;width:100%" border="1px" bordercolor="#0eb83a" >
			<tr>
					<td align="right" class="td1" nowrap>工单编号：</td>
					<td class="td2" nowrap>
						<input  id="gd_code" name="gd_code" disabled="disabled" value="<%=gd_code%>">
					</td>
					<td align="right" class="td1" nowrap>工单名称：</td>
					<td class="td2" nowrap>
						<input  id="gd_name" name="gd_name" disabled="disabled" value="<%=gd_name%>">
					</td>
				</tr>
				<tr>
					 <td align="right" nowrap class="td1">
						交底时间：
					</td>
					<td class="td2" nowrap >
						<input id="description_time" name="description_time" class="easyui-datebox" data-options="required:true">
					</td>
					<td align="right" nowrap class="td1">
						交底方：
					</td>
					<td class="td2" nowrap coslpan="2">
						<input  id="description_person_name" name="description_person_name" value="<%=person %>"  readyOnly>
						<input type="hidden" id="description_person_id" name="description_person_id" value="<%=person_id%>">
					</td>
					
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						交底内容：
					</td>
					<td class="td2"  colspan="5">
						<input hidden id="content" name="content" />
						 <script id="editor" type="text/plain" style="width:100%;height:200px;"></script>					
			     	</td>
				</tr>
				<tr id="attaTr" style="display:none">
				      <td nowrap class="td1" td align="right">附件明细: </td>
				      <td class="td2" colspan='3'>
				        <input type="hidden" id="attachmentId" name="attachmentId">
				        <input type="hidden" id="attachmentName" name="attachmentName">
				        <span id="showAtt">
				        </span>
				      </td>
			   	 </tr>
				<tr>
			      <td nowrap class="td1" td align="right">附件：</td>
			      <td class="td2" colspan='5'>
			        	 <div id="fsUploadArea" class="flash" style="width:380px;">
						     <div id="fsUploadProgress"></div>
						     <div>
						       <input type="button" id="btnStart" class="SmallButtonW" value="开始上传" onclick="swfupload.startUpload();" disabled="disabled">&nbsp;&nbsp;
						       <input type="button" id="btnCancel" class="SmallButtonW" value="全部取消" onclick="javascript:swfupload.cancelQueue();jQuery('#fsUploadArea').hide();" disabled="disabled">&nbsp;&nbsp;
						    </div>
					      </div>
					      
						    <div id="attachment1">
					          <span id="spanButtonUpload" title="上传附件"></span>
					        </div>
			      </td>
	   		   </tr>
	   		   <%if(!"1".equals(isShow)){%>
	   		   <tr>
					<td align="right" class="td1" nowrap></td>
					<td class="td2" nowrap colspan='3'>
						<div align="left">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="addOrEditGdDescription(this);">提交</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
						</div>
					</td>
	   		   </tr>
	   		   <%} else{%>
	   		   	 <tr>
					<td align="right" class="td1" nowrap></td>
					<td class="td2" nowrap colspan='3'>
						<div align="left">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-print',plain:false" onclick="gdPrint();">打印预览</a>
						</div>
					</td>
	   		   </tr>
	   		   <%}%>
			</table>
		</form>
	</div>
	</body>
</html>


